package com.server.executor.pool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import com.server.executor.ThreadPoolConstants;
import com.server.executor.factory.NamingThreadFactory;


/**
 * Description: This is a sample class.
 *
 * @Author Simon
 */
public class OrderControlThreadPoolExecutor {

    private volatile static ThreadPoolExecutor executor;

    private OrderControlThreadPoolExecutor() {
    }

    public static ThreadPoolExecutor getInstance() {
        if (executor == null) {
            synchronized (OrderControlThreadPoolExecutor.class) {
                if (executor == null) {
                    executor = new ThreadPoolExecutor(
                            ThreadPoolConstants.CORE_POOL_SIZE,
                            ThreadPoolConstants.MAX_POOL_SIZE,
                            ThreadPoolConstants.KEEP_ALIVE_TIME,
                            TimeUnit.SECONDS,
                            new ArrayBlockingQueue<>(100),
                            new NamingThreadFactory("OrderControlThread"),
                            new ThreadPoolExecutor.CallerRunsPolicy());
                }
            }
        }
        return  executor;
    }
}
